package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entity.Collection;
import entity.User;
import service.CollectionService;
import service.UserService;
import service.impl.CollectionServiceImpl;
import service.impl.UserServiceImpl;


public class CollectionServlet extends HttpServlet {

	private CollectionService cs = new CollectionServiceImpl();
	private UserService us = new UserServiceImpl();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String name = request.getParameter("name");
		String currentName = request.getParameter("currentName");
		String modle_id = request.getParameter("modle_id");
		String price = request.getParameter("price");
		User user = us.queryUserByName(name);
		Collection c = new Collection( currentName, Double.parseDouble(price), null, user.getUserId(), Integer.parseInt(modle_id));
		int i = cs.addCollection(c);
		response.getWriter().print(i);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
